package com.eve.interceptor;
/**
 * 指定拦截内容
 * @Configuration注解：表明是一个有效的配置类
 * 重写addInterceptors方法
 * 指定要拦截的路径，这里拦截"admin"访问路径
 */

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 图片保存路径
     */
    @Value("${file-save-path}")
    private String fileSavePath;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                //过滤路径
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/admin/css/**").excludePathPatterns("/admin/fonts/**")
                .excludePathPatterns("/admin/images/**")
                .excludePathPatterns("/admin/js/**")
                .excludePathPatterns("/admin/lib/**");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * 配置资源映射
         * 意思是：如果访问的资源路径是以“/images/”开头的，
         * 就给我映射到本机的“E:/images/”这个文件夹内，去找你要的资源
         * 注意：E:/images/ 后面的 “/”一定要带上
         */
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:"+fileSavePath);
    }

}
